<?php
/**
 * Created by PhpStorm.
 * User: 17274
 * Date: 2018/3/28
 * Time: 14:21
 */

namespace app\admin\controller;

use app\admin\model\AlbumModel;
use app\admin\model\LabelsModel;
use app\admin\model\MottoModel;
use app\admin\model\YuiModel;

class Yui extends Base
{
    protected $yuiModel;
    protected $labelsModel;
    protected $labelsMaps;
    protected $albumModel;

    /*
     * 依赖注入Model
     * */
    public function __construct(YuiModel $yuiModel,LabelsModel $labelsModel,AlbumModel $albumModel){
        parent::__construct();
        $this->yuiModel=$yuiModel;
        $this->albumModel=$albumModel;
        $this->labelsModel = $labelsModel;
        $this->labelsMaps=[
            "status" => 1,
            "category" => 'album'
        ];
    }

    /*
     *  个人主页
     * */
    public function index(){
        $this->assign("index",$this->yuiModel->getIndexData());
        $this->assign("logs",$this->yuiModel->getUpdateLogsData());
        $this->assign("album",$this->yuiModel->getAlbumNew());
        return $this->fetch('yui/index');
    }

    /*
    *  记忆回廊
    * */
    public function album(){
        $labels=$this->labelsModel->getByMaps($this->labelsMaps);
        if (count($labels))
            $label=input('get.label/s',$labels->toArray()[0]['code']);
        else
            $label='none';
        $this->assign("dlabel",$label);
        $this->assign("labels",$labels);
        $this->assign("data",$this->albumModel->listAllStatusByLabel($label));
        return $this->fetch('yui/album');
    }

    /*
     *  博客中心
     * */
    public function blog(){
        $this->assign("article",$this->yuiModel->getArticleNew());
        $this->assign("timeline",$this->yuiModel->getTimeLine());
        return $this->fetch('yui/blog');
    }

    /*
     *  图文档案
     * */
    public function article(){
        $labels=$this->yuiModel->getLabels('article');
        if (count($labels))
            $labels_c=input('get.label/s',$labels[0]['code']);
        else
            $labels_c='none';
        $this->assign("dlabel",$labels_c);
        $this->assign("labels",$labels);
        $this->assign("article",$this->yuiModel->getArticleByLabel($labels_c));
        return $this->fetch('yui/article');
    }

    /*
     *  图文档案详细
     * */
    public function article_detail(){
        $id=input('get.id/d');
        $this->assign("article",$this->yuiModel->getArticleById($id));
        return $this->fetch('yui/article_detail');
    }

    /*
  *  光影缝隙
  * */
    public function video(){
        $labels=$this->yuiModel->getLabels('video');
        if (count($labels))
            $labels_c=input('get.label/s',$labels[0]['code']);
        else
            $labels_c='none';
        $this->assign("dlabel",$labels_c);
        $this->assign("labels",$labels);
        $this->assign("video",$this->yuiModel->getVideoByLabel($labels_c));
        return $this->fetch('yui/video');
    }

    /*
     *  光影缝隙详细
     * */
    public function video_detail(){
        $id=input('get.id/d');
        $this->assign("video",$this->yuiModel->getVideoById($id));
        return $this->fetch('yui/video_detail');
    }

}